import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus, {ElMessage} from 'element-plus'
import 'element-plus/dist/index.css'
// 导入ElementPlus图标
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
//导入国际化配置,中文
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import request from '@/utils/request';

const app = createApp(App)

// 注册ElementPlus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
//5.配置根路径
const BASE_URL = '';
//window里面添加的内容是全局内容，可以在任意script标签内部使用
window.BASE_URL = BASE_URL;

app.use(router);
// 注册一个全局的 afterEach 导航守卫
router.afterEach(() => {
    // 每次路由跳转完成之后，将页面滚动到顶部
    window.scrollTo(0, 0);
});
app.use(store).use(ElementPlus, {locale: zhCn,}).mount('#app')

//创建加载字典项的全局方法,加载某一个字典下的所有字典项list

window.loadDictOptions = (object,dictId)=>{
    //向后端发请求获取字典项
    request.get(BASE_URL+'/sys/dict/options?dictId='+dictId).then((response)=>{
        object.value = response.data.list

    })
}
window.loadDictOptionsByCode = (object,code)=>{
    //向后端发请求获取字典项
    request.get(BASE_URL+'/sys/dict/options?code='+code).then((response)=>{
        object.value = response.data.list
    })
}
